<% /* $Id: problems.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp"%>

<%
	HashMap<String, Object> map = new HashMap<String, Object>();
	map.put("contestId", contest.getId());
	if (!user.isAdmin())
	{
		map.put("visible", true);
		map.put("active", true);
	}
	List<ContestProblemEntry> entries = ContestProblemsModel.getEntries(map);
	Map<Long, ProblemUserScoreEntry> stat = ProblemUserScoreModel.getProblemUserEntries(contest.getId(), user.getId());
	Map<Long, ProblemEntry> problemEntriesMap = ContestProblemsModel.getContestEntriesMap(contest.getId());
	Map<Long, ContestProblemScoreEntry> contestProblemScoreEntriesMap = ContestProblemScoreModel.getContestProblemEntries(contest.getId()); 
%>


<h1 align="center">Перелік завдань</h1>

<table>
	<tr bgcolor="Gainsboro">
		<th>ID</th>
		<th>Назва</th>
		<th>Час</th>
		<th>Память</th>
		<th>Успішних спроб</th>
		<th>Всього спроб</th>
<%
	if (contest.getFinishTime().after(new Date()))
	{
%>
		<th>Дії</th>
<%
	}
%>
	</tr>

<%
	for (ContestProblemEntry problem: entries)
	{
		String color = "white";
		ProblemUserScoreEntry best = stat.get(problem.getId());
		if (best == null)
			best = new ProblemUserScoreEntry();
		if (best.getRejectedCount() > 0 || best.getAcceptedCount() > 0 || best.getPendingCount() > 0)
		{
			if (best.getAccepted())
				color = "#aaffaa";
			else if (best.getPendingCount() > 0)
				color = "#ffffaa";
			else
			color = "#ffaaaa";
		}
		ContestProblemScoreEntry statusEntry = contestProblemScoreEntriesMap.get(problem.getId());//ContestProblemScoreModel.getContestProblemEntry(contest.getId(), problem.getId());
		ProblemEntry problemEntry = problemEntriesMap.get(problem.getId());//ProblemsModel.getEntry(problem.getProblemId().toString());
		
		if (statusEntry == null)
			statusEntry = new ContestProblemScoreEntry();
%>

		<tr bgcolor="<%= color %>">
			<td align="center"><%= problem.getSid() %></td>
			<td><a href="<%= Linker.link("problem.jsp?problem_id=" + problem.getId()) %>"><%= problem.getName() %></a></td>
			<td align="center"><%= problemEntry.getTimeLimit() %> мс</td>
			<td align="center"><%= problemEntry.getMemoryLimit() %> байт</td>
			<td align="center"><a href="<%= Linker.link("submissions.jsp?problem_id=" + problem.getId()) %>&judgement=AC"><%= statusEntry.getUniqueAcceptedCount() %></a></td>
			<td align="center"><a href="<%= Linker.link("submissions.jsp?problem_id=" + problem.getId()) %>"><%=statusEntry.getUniqueAcceptedCount() + statusEntry.getUniqueRejectedCount()%></a></td>
<%
		if (contest.getFinishTime().after(new Date()))
		{
%>
			<td><a href="<%= Linker.link("submit.jsp?contest_id=" + contest.getId() + "&problem_id=" + problem.getId()) %>">Здати</a></td>
<%
		}
%>
		</tr>
<%
	}
%>
</table>

<%@ include file="footer.jsp" %>